﻿Module mdlEvaluaciones
    Public con As New clssEvaluaciones
    Public idcertificado As Integer
    Public idprueba As Integer
    Public ultimo4 As Integer
    Public ultimoboton As Integer
    Sub GetEvaluacion(ByVal forma As Form, ByVal proceso As Array)
        Dim dstRecord As New DataSet
        Dim arrRow, arrRow2 As Array
        Dim ultimo As Integer = 340
        Dim ultimo2 As Integer = 220
        Dim cons As Integer = 0
        'clssIdentidad.sEspecilidad = 5
        dstRecord.Tables.Add("tipoprueba")
        mdlCRUD.loadRecord(dstRecord, "tipoprueba", "tipoprueba", "especialidadmedica_id = '" & clssIdentidad.sEspecilidad & "'", "")
        arrRow = dstRecord.Tables("tipoprueba").Rows(0).ItemArray.ToArray

        MsgBox(clssIdentidad.sEspecilidad)

        Dim idespecialista As Integer = arrRow(0)
        If (clssIdentidad.sEspecilidad = 5) Then
            dstRecord.Tables.Add("certificaciones")
            mdlCRUD.loadRecord(dstRecord, "certificaciones", "certificaciones", "procesotramite_id = '" & proceso(0) & "'", "")
            arrRow = dstRecord.Tables("certificaciones").Rows(0).ItemArray.ToArray
            dstRecord.Tables.Add("resultado")
            mdlCRUD.loadRecord(dstRecord, "resultado", "resultado", "certificaciones_id = '" & arrRow(0) & "'", "")
            frmEvaluaciones.grbEvaluacertifi.Visible = False
            For i = 0 To dstRecord.Tables("resultado").Rows.Count - 1
                arrRow = dstRecord.Tables("resultado").Rows(i).ItemArray.ToArray
                Select Case arrRow(6)
                    Case "3" : cons = 1
                    Case "2" : cons = 2 '2
                    Case "1" : cons = 3 '3
                    Case "4" : cons = 4 '4
                End Select
                PruebaCertificador(arrRow(0), arrRow(6), forma, ultimo2, cons)
            Next i
            con.boton(1030, forma)
        Else
            dstRecord.Tables.Add("certificaciones")
            mdlCRUD.loadRecord(dstRecord, "certificaciones", "certificaciones", "procesotramite_id = '" & proceso(0) & "'", "")
            If (dstRecord.Tables("certificaciones").Rows.Count > 0) Then
                arrRow = dstRecord.Tables("certificaciones").Rows(0).ItemArray.ToArray
                idcertificado = arrRow(0)

                dstRecord.Tables.Add("prueba")
                mdlCRUD.loadRecord(dstRecord, "prueba", "prueba", "tipoprueba_id = '" & idespecialista & "'", "")
                If (dstRecord.Tables("prueba").Rows.Count > 0) Then
                    arrRow = dstRecord.Tables("prueba").Rows(0).ItemArray.ToArray
                    idprueba = arrRow(0)
                    dstRecord.Tables.Add("pruebaseccion")
                    mdlCRUD.loadRecord(dstRecord, "pruebaseccion", "pruebaseccion", "prueba_id = '" & arrRow(0) & "' ORDER BY pruebaseccion_orden", "")

                    For i = 0 To dstRecord.Tables("pruebaseccion").Rows.Count - 1
                        arrRow2 = dstRecord.Tables("pruebaseccion").Rows(i).ItemArray.ToArray
                        If (i = 0) Then
                            If (arrRow(1) = "4") Then
                                ultimo += seccionPsicologia(Nothing, Nothing, forma, ultimo)
                            End If
                        End If
                        ultimo += seccion(arrRow2, arrRow2(2), forma, ultimo)
                        If (i = 0) Then
                            If (arrRow(1) = "1") Then
                                ultimo += seccionGraficaFono(Nothing, Nothing, forma, ultimo)
                            End If
                        End If
                    Next i
                    'ultimo += con.estados("Resultados", 1, Nothing, forma, ultimo, Nothing)
                    con.boton(ultimo, forma)
                End If
            Else
                MsgBox("No Existe un tramite para el arpirante")
            End If
        End If
    End Sub
    Function seccion(ByVal Dato As Array, ByVal sec As String, ByVal forma As Form, ByVal ultimo As Integer) As Integer
        Dim dstRecord As New DataSet
        Dim alto As Integer, pos As Integer, cont As Integer, filas As Integer
        Dim arrRow As Array
        Dim grb As New System.Windows.Forms.GroupBox

        dstRecord.Tables.Add("vistapruebaseccionpregunta")
        mdlCRUD.loadRecord(dstRecord, "vistapruebaseccionpregunta", "vistapruebaseccionpregunta", "pruebaseccion_id = '" & Dato(0) & "' AND  pregunta_padre='0' ORDER BY pregunta_id", "")

        For i = 0 To dstRecord.Tables("vistapruebaseccionpregunta").Rows.Count - 1
            arrRow = dstRecord.Tables("vistapruebaseccionpregunta").Rows(i).ItemArray.ToArray
            If (arrRow(7) >= 3) Then
                If (Math.Round(arrRow(7) / 3) = 1) Then
                    filas = 4
                Else
                    filas = Math.Round(arrRow(7) / 3) + 2
                End If
            Else
                If (arrRow(4) = 1) Then
                    filas += 1
                End If
            End If
        Next i
        alto = filas * 45

        grb.Location = New System.Drawing.Point(20, ultimo + 10)
        grb.Size = New System.Drawing.Size(forma.Width - 100, alto)
        grb.Text = sec


        For i = 0 To dstRecord.Tables("vistapruebaseccionpregunta").Rows.Count - 1
            arrRow = dstRecord.Tables("vistapruebaseccionpregunta").Rows(i).ItemArray.ToArray
            Dim columna As String
            columna = arrRow(4)
            If (i > 0) Then
                If (columna = "1") Then
                    cont = cont + 1
                    pos = 10 + (cont * 30)
                End If
            Else
                pos = 10
            End If
            Preguntas(arrRow(3), arrRow(4), arrRow(5), arrRow(2), grb, pos, IIf(IsDBNull(arrRow(9)), "", arrRow(9)))
        Next i

        forma.Controls.Add(grb)
        Return grb.Height
    End Function
    Sub Preguntas(ByVal nombre As String, ByVal columna As Integer, ByVal tipo As String, ByVal id As String, ByVal grupo As System.Windows.Forms.GroupBox, ByVal posicion As Integer, ByVal idOLP As String)
        Dim dstRecord As New DataSet
        Dim arrRow As Array
        dstRecord.Tables.Add("pregunta")
        mdlCRUD.loadRecord(dstRecord, "pregunta", "pregunta", "pregunta_padre = '" & id & "'", "")
        If dstRecord.Tables("pregunta").Rows.Count > 0 Then
            con.multiple(nombre, columna, id, grupo, posicion, tipo, idOLP)
        Else
            Select Case tipo
                Case "1" 'texto 
                    con.texto(nombre, columna, id, grupo, posicion, idOLP)
                Case "2" 'radio
                    con.radio(nombre, columna, id, grupo, posicion, idOLP)
                Case "3" 'seleccion
                    con.seleccion(nombre, columna, id, grupo, posicion, idOLP)
                Case "4" 'cheke 
                    con.cheke(nombre, columna, id, grupo, posicion, idOLP)
                Case "5" 'textoarea
                    con.textoArea(nombre, columna, id, grupo, posicion, idOLP)
            End Select
        End If
    End Sub
    Function seccionGraficaFono(ByVal Dato As Array, ByVal sec As String, ByVal forma As Form, ByVal ultimo As Integer) As Integer
        Dim dstRecord As New DataSet
        Dim arrRow As Array
        Dim alto As Integer, pos As Integer, cont As Integer, filas As Integer
        Dim confEvaluacion As New clssEvaluaciones
        Dim grb As New System.Windows.Forms.GroupBox

        alto = 500
        grb.Location = New System.Drawing.Point(20, ultimo + 10)
        grb.Size = New System.Drawing.Size(forma.Width - 100, alto)
        grb.Text = "CAPACIDAD AUDITIVA AEREA"

        dstRecord.Tables.Add("equipousuario")
        mdlCRUD.loadRecord(dstRecord, "equipousuario", "equipousuario", "usuario_id ='" & clssIdentidad.sID & "'", "")
        arrRow = dstRecord.Tables("equipousuario").Rows(0).ItemArray.ToArray
        confEvaluacion.graficaFonoaudologia(grb, arrRow(2), Nothing)

        forma.Controls.Add(grb)
        Return grb.Height
    End Function
    Function seccionPsicologia(ByVal Dato As Array, ByVal sec As String, ByVal forma As Form, ByVal ultimo As Integer) As Integer
        Dim confEvaluacion As New clssEvaluaciones
        Dim grb1 As New System.Windows.Forms.GroupBox
        grb1.Location = New System.Drawing.Point(20, ultimo + 10)
        grb1.Size = New System.Drawing.Size(forma.Width - 100, 100)
        grb1.Text = "Aptitud Receptivo - Motora"
        confEvaluacion.datosPsicologia("", Nothing, 3, grb1, Nothing, Nothing, ultimo)
        ultimo = grb1.Size.Height + grb1.Location.Y
        forma.Controls.Add(grb1)
        Dim grb2 As New System.Windows.Forms.GroupBox
        grb2.Location = New System.Drawing.Point(20, ultimo + 5)
        grb2.Size = New System.Drawing.Size(forma.Width - 100, 70)
        grb2.Text = "personalidad"
        confEvaluacion.datospruebaPsicologia("", Nothing, 3, grb2, Nothing, Nothing, ultimo)
        ultimo = grb2.Height + 120
        forma.Controls.Add(grb2)
        Return ultimo
    End Function
    Function PruebaCertificador(ByVal Dato As Integer, ByVal sec As String, ByVal forma As Form, ByVal ultimo As Integer, ByVal pos As Integer) As Integer
        Dim dstRecord As New DataSet
        Dim alto As Integer, y As Integer, cont As Integer, filas As Integer, wid As Integer, gid As Integer
        Dim arrRow As Array
        Dim grb As New System.Windows.Forms.GroupBox
        Dim lab1, lab2, lab3, lab4 As Label
        Dim evaluacion As New clssEvaluaciones
        Dim Rootobject() As clssEvaluaciones.sessionR
        Dim nombprueba As String
        Dim idusuario As Integer
        Dim conarr1 = 0, conarr2 As Integer = 0
        Dim arrgra1() As String
        Dim arrgra2() As String

        dstRecord.Tables.Add("prueba")
        mdlCRUD.loadRecord(dstRecord, "prueba", "prueba", "prueba_id = '" & sec & "'", Nothing)
        arrRow = dstRecord.Tables("prueba").Rows(0).ItemArray.ToArray
        nombprueba = arrRow(2)
        Select Case pos
            Case "1"
                wid = (forma.Width / 2) - 100
                alto = 1230
                grb.Location = New System.Drawing.Point(20, ultimo + 10)
            Case "2"
                wid = (forma.Width / 2) - 10
                ultimoboton += ultimo
                alto = 400
                grb.Location = New System.Drawing.Point((forma.Width / 2) - 70, ultimo + 10)
                ultimo4 = alto + grb.Location.Y
            Case "3"
                wid = (forma.Width / 2) - 10
                alto = 400
                grb.Location = New System.Drawing.Point((forma.Width / 2) - 70, ultimo4)
            Case "4"
                wid = (forma.Width / 2) - 10
                alto = 400
                grb.Location = New System.Drawing.Point((forma.Width / 2) - 70, 1030)
        End Select

        grb.Size = New System.Drawing.Size(wid, alto)
        grb.Text = arrRow(2)

        dstRecord.Tables.Add("resultado")
        mdlCRUD.loadRecord(dstRecord, "resultado", "resultado", "resultado_id = '" & Dato & "'", Nothing)
        arrRow = dstRecord.Tables("resultado").Rows(0).ItemArray.ToArray
        If (dstRecord.Tables("resultado").Rows.Count > 0) Then
            If (Not IsDBNull(arrRow(7))) Then
                idusuario = arrRow(7)
            End If
        End If
        Rootobject = evaluacion.getEvaluacion(arrRow(3).ToString)
        cont = 0
        Dim eval As New clssEvaluaciones
        For i = Rootobject.Count - 1 To 0 Step -1
            'ultimo += detalleEvaluacion(Rootobject(i).id.ToString, Rootobject(i).ojb, forma, ultimo)
            Dim pregrunta() As Pregunta = Rootobject(i).ojb
            For j = 0 To pregrunta.Count - 1
                cont = cont + 15
                pregrunta(j).id.ToString()

                Dim dstRecord2 As New DataSet
                dstRecord2.Tables.Add("pregunta")
                mdlCRUD.loadRecord(dstRecord2, "pregunta", "pregunta", "pregunta_id = '" & pregrunta(j).id & "'", "")
                If (dstRecord2.Tables("pregunta").Rows.Count > 0) Then
                    arrRow = dstRecord2.Tables("pregunta").Rows(0).ItemArray.ToArray

                    lab1 = New System.Windows.Forms.Label
                    lab1.Location = New System.Drawing.Point(10, cont)
                    lab1.Font = New Font(lab1.Name, 6.2, FontStyle.Regular)
                    lab1.Text = IIf(pos <> 1, Rootobject(i).id.ToString, arrRow(1))
                    gid = IIf(pos <> 1, 180, 220)
                    lab1.Size = New System.Drawing.Size(gid, 15)
                    filas = lab1.Location.X + lab1.Size.Width
                    grb.Controls.Add(lab1)

                    If (pos <> 1) Then
                        lab2 = New System.Windows.Forms.Label
                        lab2.Location = New System.Drawing.Point(filas, cont)
                        lab2.Font = New Font(lab2.Name, 6.5, FontStyle.Regular)
                        lab2.Text = arrRow(1)
                        lab2.Size = New System.Drawing.Size(120, 15)
                        filas = lab2.Location.X + lab2.Size.Width
                        grb.Controls.Add(lab2)
                    End If

                    lab3 = New System.Windows.Forms.Label
                    lab3.Location = New System.Drawing.Point(filas, cont)
                    lab3.Text = ""
                    lab3.Size = New System.Drawing.Size(100, 20)
                    filas = lab3.Location.X + lab3.Size.Width
                    grb.Controls.Add(lab3)

                    lab4 = New System.Windows.Forms.Label
                    lab4.Location = New System.Drawing.Point(filas, cont)
                    lab4.Text = pregrunta(j).respuesta
                    lab4.Font = New Font(lab4.Name, 6.5, FontStyle.Regular)
                    lab4.Size = New System.Drawing.Size(60, 15)
                    filas = lab4.Location.X + lab4.Size.Width
                    grb.Controls.Add(lab4)
                End If
                'End If
            Next j
        Next i

        lab3 = New System.Windows.Forms.Label
        lab3.Location = New System.Drawing.Point(10, cont + 20)
        lab3.Text = nombprueba
        lab3.Size = New System.Drawing.Size(100, 20)
        filas = lab3.Location.Y + lab3.Size.Height
        grb.Controls.Add(lab3)

        If (idusuario) Then
            dstRecord.Tables.Add("usuario")
            mdlCRUD.loadRecord(dstRecord, "usuario", "usuario", "usuario_id = '" & idusuario & "'", Nothing)
            arrRow = dstRecord.Tables("usuario").Rows(0).ItemArray.ToArray
        End If

        lab3 = New System.Windows.Forms.Label
        lab3.Location = New System.Drawing.Point(10, filas)
        lab3.Text = arrRow(9) & " " & arrRow(10) & " " & arrRow(11)
        lab3.Size = New System.Drawing.Size(200, 20)
        filas = lab3.Location.X + lab3.Size.Width
        lab4.Font = New Font(lab4.Name, 6.5, FontStyle.Regular)
        grb.Controls.Add(lab3)

        forma.Controls.Add(grb)
        Return ultimo
    End Function
End Module


